package com.hc.conferencecheck.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 用于校验手机号码的工具类
 */
public class PhoneNumberUtils {
    /**以及手机号格式
     * 校验手机号长度
     *
     * @param phone
     * @return
     */
    public static Boolean matchPhoneNumber(String phone) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (phone.length() != 11) {
            System.out.println("手机号应为11位数");
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            if (!isMatch) {
                System.out.println("手机号格式错误");
                return false;
            } else {
                System.out.println("手机号格式正确");
                return true;
            }
        }
    }
}
